//
var admin_UserManagement = function() {
    $('#adminUserManagementAddUserDialog').dialog({
        width: 350,
        autoOpen: false,
        modal: true,
        title: 'Add New User',
        buttons: {
            OK: function() {
                var username = document.getElementById('adminUserManagementAddUserAccountField').value;
                var firstName = document.getElementById('adminUserManagementAddUserFirstNameField').value;
                var lastName = document.getElementById('adminUserManagementAddUserLastNameField').value;
                var email = document.getElementById('adminUserManagementAddUserEmailField').value;
                var enableIaaS = document.getElementById('adminUserManagementAddUserServiceTypeIaaSCheckbox').checked;
                var enableHPC = document.getElementById('adminUserManagementAddUserServiceTypeHPCCheckbox').checked;
                var enableWebHosting = document.getElementById('adminUserManagementAddUserServiceTypeWebHostingCheckbox').checked;
                var password = document.getElementById('adminUserManagementAddUserPasswordField').value;
                var confirm = document.getElementById('adminUserManagementAddUserPasswordConfirmField').value;
                var this_ = this;
                if (password !== confirm) {
                    alert('Password doesn\'t match.');
                    return;
                }
                $.post('/users.json', { 
                    username: username,
                    firstName: firstName,
                    lastName: lastName,
                    email: email,
                    enableIaaS: enableIaaS,
                    enableHPC: enableHPC,
                    enableWebHosting: enableWebHosting,
                    password: password,
                    confirm: confirm
                }, function(serverResponse) {
                    var signupSucceeded = (serverResponse === 'registration successful');
                    $(this_).dialog("close");
                    alert(serverResponse);
                }, 'json');
            },

            Cancel: function() {
                $(this).dialog("close");
            }
        }
    });

    $('#adminUserManagementAddButton').click(function(event) {
        $('#adminUserManagementAddUserDialog').dialog('open');
    });
};